package parser

import (
	"errors"
	"project/schedule/model"
)

func ParseAuditRule(general *model.General, body *map[string]interface{}) error {
	auditRule, ok := (*body)["auditRule"]
	if !ok {
		return errors.New("no auditRule in body")
	}
	for role, roleInfo := range auditRule.(map[string]interface{}) {
		general.AuditRule[role] = make(map[string]map[string]int)
		for audit, auditInfo := range roleInfo.(map[string]interface{}) {
			general.AuditRule[role][audit] = make(map[string]int)
			for week, weekInfo := range auditInfo.(map[string]interface{}) {
				general.AuditRule[role][audit][week] = int(weekInfo.(float64))
			}
		}
	}
	return nil
}
